<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>03postaddgrade</title>
    <script type="text/javascript" src="../js/vue.js"></script>
    <script type="text/javascript" src="../js/axios.min.js"></script>
</head>

<body>
    <div id="app">
        <form>
            班级id:<input type="text" placeholder="请输入班级id" v-model="grade.id"><br>
            班级名称:<input type="text" placeholder="请输入班级名称" v-model="grade.name"><br>
            课程数量:<input type="text" placeholder="请输入课程数量" v-model="grade.coursenum"><br>
            <!--必须使用<input type="button">。<button>组件不起效!!! -->
            <input type="button" @click="addGrade" value="确定">
        </form>
    </div>
</body>

</html>
<script>
    var vm = new Vue({
        el: '#app',
        data: {
            grade: {
                id: '',
                name: '',
                coursenum: ''
            },
            url: 'http://localhost/grade/addGrade'
        },
        methods: {
            addGrade() {
                axios({
                    /*post请求必须使用method:'post'，使用type就报错*/
                    method: 'post',
                    url: this.url,
                    data: this.grade
                }).then(res => {
                    console.log(res);
                });
            }
        }
    });
</script>